$(function(){
	medicalOrderList();
	
	function medicalOrderList(medicalid){
		if(medicalid == undefined){
			medicalid= utilModule.getQueryString("shipping_status");
		}
		if(medicalid==5){
 			var param = {"userId":USERID,"payStatus":1};
		}else{
			if(medicalid==4){
				var param = {"userId":USERID,"orderStatus":4,"payStatus":1};
			}else{
				var param = {"userId":USERID,"orderStatus":1,"shipping_status":medicalid,"payStatus":1};
			}
 			
		}
		$("[type='"+medicalid+"']").addClass("active");

		function callBackSlider(data){
			console.log(data);
			if(data.result==""){
				$(".order-noData").show();
				$(".order-list ul li").hide();
			}else{
				$(".order-noData").hide();
				var html="";
				for(i in data){
 					html +=	'<li orderId="'+data[i].id+'" money="'+data[i].goodsAmount+'" expressExt="'+data[i].expressExt+'" expressNumber="'+data[i].expressNumber+'"><div class="orderTitle">'+data[i].realname+'-处方单';
					if(data[i].shippingStatus==0){
						html += '<span class="color_orange">未发货</span></div>';
						html +='<div class="orderTime">诊断时间：'+data[i].addTime+'</div><div class="orderContent">';
						html +='<div class="orderPicture">';
						for(j in data[i].prescriptionDetailList){
							html += '<div><img src="'+data[i].prescriptionDetailList[j].thumbnail+'"/></div>';
						}
						html +='</div>';
						if(data[i].prescriptionDetailList.length>3){
							html += '<div class="orderMore">...</div>';
						}
						html +='</div><div class="orderOperation"><font>共'+data[i].prescriptionDetailList.length+'件商品<i>总价：<em class="color_blue">¥'+data[i].goodsAmount+'</em></i></font></div></li>';
					}else if(data[i].shippingStatus==1){
						html += '<span class="color_orange">已发货</span></div>';
						html +='<div class="orderTime">诊断时间：'+data[i].addTime+'</div><div class="orderContent">';
						html +='<div class="orderPicture">';
						for(j in data[i].prescriptionDetailList){
							html += '<div><img src="'+data[i].prescriptionDetailList[j].thumbnail+'"/></div>';
						}
						html +='</div>';
						if(data[i].prescriptionDetailList.length>3){
							html += '<div class="orderMore">...</div>';
						}
						html +='</div><div class="orderOperation"><font>共'+data[i].prescriptionDetailList.length+'件商品<i>总价：<em class="color_blue">¥'+data[i].goodsAmount+'</em></i></font><span><button class="lookLogistics">查看物流</button><button class="shulClick">确认收货</button></span></div></li>';
					}else if(data[i].shippingStatus==2){
						html += '<span class="color_blue">已收货</span></div>';
						html +='<div class="orderTime">诊断时间：'+data[i].addTime+'</div><div class="orderContent">';
						html +='<div class="orderPicture">';
						for(j in data[i].prescriptionDetailList){
							html += '<div><img src="'+data[i].prescriptionDetailList[j].thumbnail+'"/></div>';
						}
						html +='</div>';
						if(data[i].prescriptionDetailList.length>3){
							html += '<div class="orderMore">...</div>';
						}
						html +='</div><div class="orderOperation"><font>共'+data[i].prescriptionDetailList.length+'件商品<i>总价：<em class="color_blue">¥'+data[i].goodsAmount+'</em></i></font><span><button class="customer">售后</button></span></div></li>';
					}else if(data[i].shippingStatus==4){
						html += '<span class="color_blue">已收货</span></div>';
						html +='<div class="orderTime">诊断时间：'+data[i].addTime+'</div><div class="orderContent">';
						html +='<div class="orderPicture">';
						for(j in data[i].prescriptionDetailList){
							html += '<div><img src="'+data[i].prescriptionDetailList[j].thumbnail+'"/></div>';
						}
						html +='</div>';
						if(data[i].prescriptionDetailList.length>3){
							html += '<div class="orderMore">...</div>';
						}
						html +='</div><div class="orderOperation"><font>共'+data[i].prescriptionDetailList.length+'件商品<i>总价：<em class="color_blue">¥'+data[i].goodsAmount+'</em></i></font><span><button>审核中..</button></span></div></li>';
					}else if(data[i].shippingStatus==6){
						html += '<span class="color_blue">已收货</span></div>';
						html +='<div class="orderTime">诊断时间：'+data[i].addTime+'</div><div class="orderContent">';
						html +='<div class="orderPicture">';
						for(j in data[i].prescriptionDetailList){
							html += '<div><img src="'+data[i].prescriptionDetailList[j].thumbnail+'"/></div>';
						}
						html +='</div>';
						if(data[i].prescriptionDetailList.length>3){
							html += '<div class="orderMore">...</div>';
						}
						html +='</div><div class="orderOperation"><font>共'+data[i].prescriptionDetailList.length+'件商品<i>总价：<em class="color_blue">¥'+data[i].goodsAmount+'</em></i></font><span><button class="customerWrite">售后进度</button></span></div></li>';
					}else if(data[i].shippingStatus==7){
						html += '<span class="color_blue">已收货</span></div>';
						html +='<div class="orderTime">诊断时间：'+data[i].addTime+'</div><div class="orderContent">';
						html +='<div class="orderPicture">';
						for(j in data[i].prescriptionDetailList){
							html += '<div><img src="'+data[i].prescriptionDetailList[j].thumbnail+'"/></div>';
						}
						html +='</div>';
						if(data[i].prescriptionDetailList.length>3){
							html += '<div class="orderMore">...</div>';
						}
						html +='</div><div class="orderOperation"><font>共'+data[i].prescriptionDetailList.length+'件商品<i>总价：<em class="color_blue">¥'+data[i].goodsAmount+'</em></i></font></div></li>';
					}
				}
				$(".order-list ul").empty();
				$(".order-list ul").append(html);
				
				$(".order-list ul li").on("click",function(event){
					event.stopPropagation();
					var orderId=$(this).attr("orderid");
					location.href = "../../html/onlineContinuation/look-logistics.html?orderid="+orderId;
				});
				
				$(".lookLogistics").on("click",function(event){
					event.stopPropagation();
					var orderId=$(this).parent().parent().parent().attr("orderid");
					var expressNumber=$(this).parent().parent().parent().attr("expressNumber");
					var expressext=$(this).parent().parent().parent().attr("expressext").split(",");
					location.href = 'https://m.kuaidi100.com/index_all.html?type='+expressext[1]+'&postid='+expressNumber+'&callbackurl='+serverUrl+'n/html/onlineContinuation/my-order.html';
					//location.href = "../../html/onlineContinuation/send-express.html?orderid="+orderId;
				});
				
				$(".shulClick").on("click",function(event){
					event.stopPropagation();
					var orderId=$(this).parent().parent().parent().attr("orderid");
					var btnArray = ['否', '是'];
					mui.confirm('确认已收到货物？', '提示', btnArray, function(e) {
						if(e.index == 1) {
							var shulparam={"id":orderId,"shippingStatus":2}
							onlineContinuationModule.updateMallOrderList(shulparam,shulcallBack);
							function shulcallBack(json){
								if(json==1){
									location.reload(true);
									mui.toast("收货成功"); 
								}else{
									mui.toast("收货失败"); 
								}
							}
						}
					})
				});
				$(".customer").on("click",function(event){
					event.stopPropagation();
					var orderId=$(this).parent().parent().parent().attr("orderid");
					var money=$(this).parent().parent().parent().attr("money");
					location.href = "../../html/onlineContinuation/customer-service.html?orderid="+orderId+"&money="+money;
				});
				
				$(".customerWrite").on("click",function(event){
					event.stopPropagation();
					var orderId=$(this).parent().parent().parent().attr("orderid");
					var order = {"orderId":orderId};
					onlineContinuationModule.getmalltuihuo(order,recordBackSlider);
					function recordBackSlider(record){
						console.log(record);
						if(record.status==1 && typeof(record.returnEcompany)=="undefined"){
							location.href = "../../html/onlineContinuation/write-express.html?orderId="+orderId;
						}else{
							location.href = "../../html/onlineContinuation/return-logistics.html?orderId="+orderId;
						}
					}
				});
			}
		}
		onlineContinuationModule.getMallOrderList(param,callBackSlider);
	}
	
	$(".order-noData button").on("click",function(){
		location.href = "../../html/onlineContinuation/my-prescription.html";
	});
	
	$(".order-header div span").on("click",function(){
		var number = $(this).parent().attr("type");
		medicalOrderList(number);
		$(this).parent().siblings().removeClass("active");
	});
	
});
